export default {
	data() {
		return {
			e: null,
			ScrollView: null,
		}
	},
	methods: {
		runCommand(e) {
			if (e == null)return
			this.e = e;
			this.getScrollView(document.getElementById(`EDragList_${e.id}`))
			window.cancelAnimationFrame(this.AnimationFrameID);
			this.AnimationFrameID = window.requestAnimationFrame(this.Animation);
			if (e.command == "stop") {
				window.cancelAnimationFrame(this.AnimationFrameID);
				return;
			}
		},
		Animation() {
			if (this.e.command == "stop") {
				window.cancelAnimationFrame(this.AnimationFrameID);
				return;
			}
			// 计算最大滚动高度
			let maxScrollTop = this.e.length * this.e.itemHeight - this.e.scrollHeight;
			if (this.e.command == "up") {
				this.ScrollView.scrollTop -= 3
			} else if (this.e.command == "down") {
				this.ScrollView.scrollTop += 3;
			}
			if (this.ScrollView.scrollTop < 0) {
				this.ScrollView.scrollTop = 0;
				window.cancelAnimationFrame(this.AnimationFrameID);
			}
			if (this.ScrollView.scrollTop > maxScrollTop) {
				this.ScrollView.scrollTop = maxScrollTop;
				window.cancelAnimationFrame(this.AnimationFrameID);
			}
			this.AnimationFrameID = window.requestAnimationFrame(this.Animation);
		},
		getScrollView(DOM) {
			if (this.ScrollView != null) {
				return this.ScrollView;
			}
			let styleStr = DOM.getAttribute('style');

			if (DOM.className == 'uni-scroll-view' && styleStr != null && styleStr.indexOf('overflow') > -1 && styleStr
				.indexOf(
					'auto') > -1) {
				this.ScrollView = DOM;
				return DOM;
			} else {
				this.getScrollView(DOM.firstChild);
			}
		}
	}

}
